/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1601635833823_3696';

  // add your middleware config here
  config.middleware = ['errorHandler'];
  
  config.security = {
	  csrf: {
		  enable: false, // 默认为 false，当设置为 true 时，将会放过所有 content-type 为 `application/json` 的请求
	  }
  }
  
  //配置不需要验证token的路由
  config.errorHandler = {
		isOpen: true, // 是否开启token验证
		allowed: [
			'/api/v1/login',
			'/api/v1/logout'
		]
  }

  // add your user config here
  const userConfig = {
		// 用户信息
    user: {}
	};
	
	// 跨域配置
	config.cors = {
		origin: '*',
		allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
	}

	config.cluster = {
		listen: {
			port: 7991
		}
	}
  
	// 数据库连接配置
  config.mysql = {
		client: {
			host: '127.0.0.1',
			port: '3306',
			user: 'root',
			password: '123456',
			database: 'article_manager'
		},
		app: true,
		agent: false
  }
  
  config.validatePlus = {
	  resolveError(ctx,errors){
		  if(errors.length){
			  ctx.status = 400
			  ctx.body = {
				  errorCode: 20001,
				  msg: '参数错误',
				  errors
			  }
		  }
	  }
  }
  
  config.jwt = {
	  secret: 'EGGAPI',
	  expiresIn: 60 * 30
  }
  
  config.redis = {
	  client: {
		  port: 6379,
		  host: '127.0.0.1',
		  password: '',
		  db: 0
	  }
  }

  return {
    ...config,
    ...userConfig,
  };
};
